﻿using MediatR;
using SlaughterItem.Common.Domains.PORk;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace GetSlaughterItem.API.Application.Commands.Week03.Reports
{
    public class WhiteporkCollectQueryHandler : IRequestHandler<WhiteporkCollectQueryCommand, Result>
    {
        /// <summary>
        /// 白条称重明细
        /// </summary>
        private readonly IBaseRepositoryGet<WhiteporkData> whiteporkDatarepository;

        public WhiteporkCollectQueryHandler(IBaseRepositoryGet<WhiteporkData> whiteporkDatarepository)
        {
            this.whiteporkDatarepository = whiteporkDatarepository;
        }

        public async Task<Result> Handle(WhiteporkCollectQueryCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Success };

            var list = whiteporkDatarepository.GetAll().ToList();
            //var list = (from a in whiteporkDatarepository.GetAll()
            //            group a by new { a.GoodsMinute }
            //            //,a.WhiteWeighingDate, a.WeighingNum, a.SkinWeight, a.GrossWeight, a.NetWeight 
            //           into b
            //            select new 
            //            {
            //                b.Key.GoodsMinute,
            //                SumCount = b.Sum(x => x.WeighingNum),
            //                SkinWeight = b.Average(x => x.SkinWeight),
            //                GrossWeight = b.Average(x => x.GrossWeight),
            //                NetWeight = b.Average(x => x.NetWeight)
            //            }).OrderByDescending(x => x.GoodsMinute).ToList();


            result.Data = list;
            return result;

        }
    }
}
